//
//  ECUIView_TVSelected.m
//  Edu_iOS
//
//  Created by yanyan on 2017/9/13.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECUIView_TVSelected.h"
#import "CategoryModel.h"
@interface ECUITVCell_RightSelected()
@property(nonatomic,strong)UIImageView *selectedImageView;
@end
@implementation ECUITVCell_RightSelected
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectedImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tvcell_rightSelected"]];
        self.selectedImageView.frame = CGRectMake(kScreenWidth - 40, 50/2-11*kPercentage/2,12*kPercentage , 11*kPercentage);
        self.selectedBackgroundView = [[UIView alloc]init];
        [self.selectedBackgroundView addSubview:self.selectedImageView];
        self.textLabel.textAlignment = NSTextAlignmentCenter;
        self.textLabel.highlightedTextColor = ECTHEMESELECTEDCOLOR;
    }
    return self;
}


@end

@interface ECUIView_TVSelected()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@end
@implementation ECUIView_TVSelected

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
 - (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame))];
        _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithRed:0.9451 green:0.9490 blue:0.9569 alpha:1];
        [_tableView registerClass:[ECUITVCell_RightSelected class] forCellReuseIdentifier:@"cell"];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        self.tableView.rowHeight = 50;
        [self addSubview:_tableView];
    }
    return self;
}
#pragma mark -TableView Delegate -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.object count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    PrimaryCategoryModel *mo = [self.object objectAtIndex:indexPath.row];
    cell.textLabel.text = mo.title;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.block_selected) {
        self.block_selected([self.object objectAtIndex:indexPath.row]);
    }
}
@end
